
;;; fold multiple dimension list to single demension list
;;; any build-in function?
;;; stack overflow when alist contains a large amount of items
(defun fold-list-recur (alist)
  (if (zerop (length alist)) alist
	  (append (car alist) (fold-list-recur (cdr alist)))))

(defun fold-list-iteractive (alist)
	(do ((result '() (append result (car tmplist)))
		 (tmplist alist (cdr tmplist)))
	    ((null tmplist) result)))

(defun flatten-list (alist)
  (reduce
    (lambda (x y) (append x y))
    alist))

(defparameter *alist* '((1 2 3) (4 5 6) (7 8 9)))

(format t "~a~%" (time (fold-list-recur *alist*)))
(format t "~a~%" (time (flatten-list *alist*)))
